<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("basePath", basePath);
String respondResultJson = (String)request.getAttribute("respondResultJson");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>解放军第三〇五医院</title>
	<style>
		#box{width:1200px;height:1000px;margin:200px auto;}
	</style>
	
	<link rel="stylesheet" href="${basePath}assets/bootstrap/css/bootstrap.css"/>
	<script type="text/javascript" src="${basePath}assets/js/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="${basePath}assets/bootstrap/js/bootstrap.js"></script>
	<script type="text/javascript" src="${basePath}assets/layer/layer.js"></script>
	<link href="${basePath}assets/css/basic.css" rel="stylesheet" type="text/css">
	<link rel="stylesheet" href="${basePath}assets/css/list.css"/>
	<link rel="stylesheet" href="${basePath}assets/css/login.css"/>
	<script type="text/javascript" src="${basePath}assets/js/header.js"></script>
	
	
</head>
<body>
 <input type="hidden" id="basePath" value="${basePath}"/>
<!--<div id="div_login" style="display:none;">-->
<div id="box">
<div id="div_login">

 <div class="login">

  <ul>
  	<form action="${basePath}user/login" method="post" id="form1">
  	
	<li>
		<p style="width: 65px; float: left;">用户名：</p>
		<p style="float: left; width: 100px;">
			<INPUT style="float: none;" name="loginName" id="loginName" type="text" class="textbox" value="${loginName }">
		</p>
	</li>
	
	<li>
		<p style="width: 65px; float: left;">密&nbsp;&nbsp; 码：</p>
		<p style="float: left; width: 100px;">
			<INPUT style="float: none;" name="password"
			id="txtPwd" type="password" class="textbox" value="${password }">
		</p>
	</li>
	<li><span onclick="createCode()" style="letter-spacing:5px" id="checkCode"></span>
		验证码：&nbsp;&nbsp;<INPUT name="txtName" id="txtName" type="text" class="check" value="">
	</li>
  	 <li><a><INPUT name="btnLogin" class="L_up" id="btn_login" onclick="login()"
			type="button" value="登&nbsp;&nbsp;录"></a> <a><INPUT
			name="btnLogin" class="L_up2" id="closeBtn" type="button"
			value="重&nbsp;&nbsp;置"></a></li>
   </form>
 </ul>
 </div>

</div>
</div>
</body>
<script type="text/javascript">

 	$("#closeBtn").on('click',function(){
		$("#loginName").val("");
		$("#txtPwd").val("");
		$("#txtName").val("");
		createCode();
	});
	$(function(){
		createCode();
		var respondResultJson= <%=respondResultJson%>;
		console.log(respondResultJson);
		if(respondResultJson){
			if(respondResultJson.success == false){
				if(respondResultJson.stateCode == "403"){
					layer.msg(respondResultJson.stateMessage);
				}else if(respondResultJson.stateCode == "500"){
					layer.msg(respondResultJson.stateMessage);
				}
			}
		}
		var basePath = $("#basePath").val();
		if(parent.document.getElementById("mainContent")){
			parent.location.href=basePath+"user/loginForm";
		}
	});

	var code; //在全局 定义验证码    
    function createCode() {  
        code = "";  
        var codeLength = 4;//验证码的长度       
  
        var selectChar = new Array(2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D',  
                'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R',  
                'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');  
  
        for (var i = 0; i < codeLength; i++) {  
            var charIndex = Math.floor(Math.random() * 32);  
            code += selectChar[charIndex];  
        }  
        if (code.length != codeLength) {  
            createCode();  
        }  
        $("#checkCode").html(code);  
    }  
  
    function validate() {  
        var inputCode = document.getElementById('txtName').value.toUpperCase();
        if (inputCode.length <= 0) {  
            alert("请输入验证码！");  
            return false;  
        } else if (inputCode != code) {  
            alert("验证码输入错误！");  
            createCode();  
            return false;  
        } else {  
            return true;  
        }  
  
    }  
    
    
    function login(){
    	var userName= $("#loginName").val();
    	var password=$("#txtPwd").val();
    	if(!userName){
    		alert("用户名不能为空!");
    		return;
    	}
    	if(!password){
    		alert("密码不能为空!");
    		return;
    	}
    	//校验验证码登陆
    	if(validate()){
    		$("#form1").submit();
    	}
    	
    }
</script>
</html>
